
let tableIns;
let tree;
layui.use(['table', 'form','layer', 'laydate', 'tree', 'util'], function () {
    let table = layui.table , form = layui.form;
    tree = layui.tree;
    let height = document.documentElement.clientHeight - 60;


    tableIns = table.render({
        elem: '#withdrawTable'
        , url: '/platform/agent/withdraw/list/page'
        , method: 'GET'
        //请求前参数处理
        , request: {
            pageName: 'page' //页码的参数名称，默认：page
            , limitName: 'rows' //每页数据量的参数名，默认：limit
        }
        , response: {
            statusName: 'flag' //规定数据状态的字段名称，默认：code
            , statusCode: true //规定成功的状态码，默认：0
            , msgName: 'msg' //规定状态信息的字段名称，默认：msg
            , countName: 'records' //规定数据总数的字段名称，默认：count
            , dataName: 'rows' //规定数据列表的字段名称，默认：data
        }
        //响应后数据处理
        , parseData: function (res) { //res 即为原始返回的数据
            var data = res.data;
            return {
                "flag": res.flag, //解析接口状态
                "msg": res.msg, //解析提示文本
                "records": data.records, //解析数据长度
                "rows": data.rows //解析数据列表
            };
        }
        , title: '提现核审'
        , cols: [[
            {field: 'agentId', title: 'ID', hide: true}
            , {field: 'orderId', title: '订单号'}
            , {field: 'accountName',title: '代理商名称'}
            , {field: 'bankAccount',title: '银行账户'}
            , {field: 'bankName', title: '银行名称'}
            , {field: 'cashAmount', title: '提现金额' ,
                templet: function(d){return formatMoney(d.cashAmount);}}
            , {field: 'theTaxPayableAmount', title: '缴税金额',
                templet: function(d){return formatMoney(d.theTaxPayableAmount);}}
            , {field: 'theAmount', title: '实际发放金额',
                templet: function(d){return formatMoney(d.theAmount);}}
            , {field: 'mobile', title: '手机号'}
            , {field: 'billImg', title: '显示发票',templet: '#bill'}
            ,{title: '操作' ,toolbar: '#barBtn'}
        ]]
        , defaultToolbar: ['', '', '']
        , page: true
        , height: height
        , cellMinWidth: 80
    });

    table.on('tool(display)',function (obj) {
        var _data = obj.data;

        //通过
        if (obj.event === 'adopt') {
            layer.confirm('确认通过并放款？', function (index) {
                //向服务端发送删除指令
                $.post("/platform/agent/withdraw/update",
                    {orderId:_data.orderId,orderType:'1'}, function (data) {
                        layer.close(index);
                        location.reload();
                    })
            });
        }
        //拒绝
        else if (obj.event === 'refuse') {
            layer.confirm('确认拒绝该提现？', function (index) {
                //向服务端发送删除指令
                $.post("/platform/agent/withdraw/update",
                    {orderId:_data.orderId,orderType:'2'}, function (data) {
                        layer.close(index);
                        location.reload();
                    })
            });
        }


    });




});
function formatMoney(str) {
    if (!str) str = '0.00';
    let ret = Math.round(parseFloat(str) * 100) / 100;
    let decimal = ret.toString().split('.');
    if (decimal.length === 1) {
        return ret.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")
            + '.00';
    };
    if (decimal.length > 1) {
        decimal[0] = decimal[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
        if (decimal[1].length < 2) {
            decimal[1] += '0';
            return decimal.join(".");
        }
        return decimal.join(".");
    };
    return ret;
}

